package com.gmail.blackdog1987.onedollar.web.dto;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * @author DongGuoChao
 * @date 2014-3-28
 * @desc 通用API返回格式
 */
public class JsonResult {

	private Boolean success;
	private String msg;
	private Object record;
	private String errorCode;

	public JsonResult() {

	}

	public JsonResult(Boolean success, Object record) {
		this.success = success;
		this.record = record;
	}

	public JsonResult(Boolean success, String errorCode, String msg,
			Object record) {
		this.setErrorCode(errorCode);
		this.success = success;
		this.msg = msg;
		this.record = record;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getRecord() {
		return record;
	}

	public void setRecord(Object record) {
		this.record = record;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof JsonResult)) {
			return false;
		}
		JsonResult rhs = (JsonResult) object;
		return new EqualsBuilder().appendSuper(super.equals(object))
				.append(this.record, rhs.record).append(this.msg, rhs.msg)
				.append(this.success, rhs.success).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(1692031361, 895078645)
				.appendSuper(super.hashCode()).append(this.record)
				.append(this.msg).append(this.success).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("msg", this.msg).append("success", this.success)
				.append("record", this.record).toString();
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}
}
